import sys


def convert(file, tag, score=10000):
    # print(file)
    words = open(file, encoding='utf-8').read().split('\n')
    writer = open(file.replace('.dic', '_das.dic'), 'w', encoding='utf-8')
    for word in words:
        if word is not None and word != '':
            writer.write(word + '\t' + tag + '\t' + str(score) + '\n')
    writer.close()


def deconvert(file):
    words = open(file, encoding='utf-8').read().split('\n')
    writer = open(file.replace('.dic', '_raw.dic'), 'w', encoding='utf-8')
    for word in words:
        if word is None or word == '':
            continue
        word = word.split('\t')[0]
        writer.write(word + '\n')
    writer.close()


# convert(sys.argv[0], sys.argv[1])
# convert('specialImage/第一次维基应用科学/raw.dic', 'das_wiki_tech')
# convert('specialImage/互动百科/raw.dic', 'das_sogou_comp')
# convert('specialImage/沪深美港上市公司/raw.dic', 'das_stocks', 20000)
# convert('specialImage/维基重定向/raw.dic', 'das_wiki_redirect')

# deconvert('specialImage/第一次维基应用科学/wiki_tech.dic')


convert('../workingDir/dict/auto_baby_top10k.dic', 'auto_baby')
convert('../workingDir/dict/auto_economy_top10k.dic', 'auto_economy')
convert('../workingDir/dict/auto_tech_top10k.dic', 'auto_tech')
